//
//  TLMyVC.m
//  TLLoanSimulat
//
//  Created by mc on 2017/10/23.
//  Copyright © 2017年 mc. All rights reserved.
//

#import "TLMyVC.h"
#import "TLMyCell.h"
#import "TLLoginVC.h"
#import "TLRegistFindVC.h"

#define kTabCellID @"MyCell"
#define kKeFuCall @"023-67898642"


@interface TLMyVC ()<UITableViewDelegate,UITableViewDataSource> {
    NSArray *_dataArray;
    BOOL _isLogin;
}

@property (weak, nonatomic) IBOutlet UITableView *tableView;

@property (weak, nonatomic) IBOutlet UIView *headerViewLogout;
@property (strong, nonatomic) IBOutlet UIView *headerViewLogin;


@end

@implementation TLMyVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initUI];
    [self initData];
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark - 初始化
#pragma mark -
#pragma mark ---初始化UI
-(void)initUI {
    [self initTable];
}
-(void)setHeaderView {
    if (_isLogin) {
        [_tableView setTableHeaderView:_headerViewLogin];
        [_tableView reloadData];
        return;
    }
    [_tableView setTableHeaderView:_headerViewLogout];
    [_tableView reloadData];
}

#pragma mark ---初始化数据
-(void)initData {
    _dataArray = @[
  @[@{kImgIcon:@"", kTitle:@"VIP有效期", kCont:@"", kImgSel:@""},
                     @{kImgIcon:@"", kTitle:@"意见反馈", kCont:@"", kImgSel:@""},
                     @{kImgIcon:@"", kTitle:@"用户协议", kCont:@"", kImgSel:@""},
                     @{kImgIcon:@"", kTitle:@"在线支付", kCont:@"", kImgSel:@""},
                     @{kImgIcon:@"", kTitle:@"卡密支付", kCont:@"", kImgSel:@""},
                     ],
  @[@{kImgIcon:@"", kTitle:@"商务合作", kCont:@"", kImgSel:@""},
    ],
  @[@{kImgIcon:@"", kTitle:@"客服电话", kCont:kKeFuCall, kImgSel:@""},
    ]
  ];
    [_tableView reloadData];
}
#pragma mark - 列表
#pragma mark -
#pragma mark ---初始化 tab
- (void)initTable
{
    if ([_tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [_tableView setSeparatorInset:UIEdgeInsetsZero];
    }
    if ([_tableView respondsToSelector:@selector(setLayoutMargins:)]) {
        [_tableView setLayoutMargins:UIEdgeInsetsZero];
    }
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [_tableView setBackgroundColor:[UIColor clearColor]];
    [_tableView setTableHeaderView:_headerViewLogout];
    //分割线
//    [_tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    [self registerMyBillCell];
}


#pragma mark - 列表相关
#pragma mark -
#pragma mark ---注册CELL
- (void)registerMyBillCell
{
    ///活动列表 cell
    [_tableView registerNib:[UINib nibWithNibName:(NSStringFromClass([TLMyCell class])) bundle:nil] forCellReuseIdentifier:kTabCellID];
    [self setExtraCellLineHidden:_tableView];
}

#pragma mark ---隐藏多余的线
-(void)setExtraCellLineHidden:(UITableView *)tableView
{
    UIView *view = [UIView new];
    view.backgroundColor = [UIColor clearColor];
    [tableView setTableFooterView:view];
}

#pragma mark ---行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 40;
}

#pragma mark ---组数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    if (_isLogin) {
        return _dataArray.count;
    }
    return 1;
//    return  _dataArray.count;
}

#pragma mark ---行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (_isLogin) {
        NSArray *array = _dataArray[section];
        return array.count;
    }
    return 0;
}

#pragma mark ---组头高
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if(section==0) return 0.000000001;
    
    return 10;
}

#pragma mark ---组脚高
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.000000001;
}

#pragma mark ---行设置
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    TLMyCell *cell= [tableView dequeueReusableCellWithIdentifier:kTabCellID];
    if (!cell) {
        cell = [[TLMyCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kTabCellID];
    }
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    NSArray *arrayRow = _dataArray [indexPath.section];
    NSDictionary *dictRow = arrayRow[indexPath.row];
    [cell setCellWithDict:dictRow];
    
    return cell;
}
#pragma mark ---行 选中
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
}

#pragma mark - 请求 事件
#pragma mark -
#pragma mark ---请求
-(void)getReqFor {
}

- (IBAction)btnLoginAction:(id)sender {
    [self navigationPushViewController:[TLLoginVC class]  animation:YES withOperation:^(id vcInstance) {
        TLLoginVC *vc= vcInstance;
        vc.popToVC = self;
        [vc setLoginSuc:^{
            _isLogin = YES;
            [self setHeaderView];
        }];
    }];
}

- (IBAction)btnRegisterAction:(id)sender {
    [self navigationPushViewController:[TLRegistFindVC class]  animation:YES withOperation:^(id vcInstance) {
        TLRegistFindVC *vc= vcInstance;
        vc.popToVC = self;
        vc.isRegister = YES;
        vc.title = @"注册";
//        [vc setLoginSuc:^{
//            _isLogin = YES;
//        }];
    }];
}


@end
